package com.spark.shiro.util;


import org.apache.shiro.codec.Base64;
import org.apache.shiro.crypto.hash.Md5Hash;

/**
 * Created by tyd on 2017-10-28.
 */
public class CryptographyUtil {

    /**
     * Base64加密
     * @param str
     * @return
     */
    public static String encodeBase64(String str){
        return Base64.encodeToString(str.getBytes());
    }

    /**
     * Base64解密
     * @param str
     * @return
     */
    public static String decodeBase64(String str){
        return Base64.decodeToString(str.getBytes());
    }

    /**
     * md5加密
     * @param str
     * @param salt
     * @return
     */
    public static String md5(String str,String salt){
        return new Md5Hash(str,salt).toString();
    }

    public static void main(String[] args){

        String str = "123456";

        String encode = CryptographyUtil.encodeBase64(str);
        System.out.println(encode);

        System.out.println(CryptographyUtil.decodeBase64(encode));

        System.out.println(CryptographyUtil.md5(str,"spark"));
    }
}
